Thread: map with char[30] as key

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Roughly speaking, templates cannot be instantiated using types that are local to a function.

    The fact you are mixing C techniques with C++ techniques will make your code very error prone. Even if the compiler doesn't complain, it is a very poor idea to use an array of char as keys for a map. It's akin to the argument of having to use strcmp() function to compare strings in C, rather than the == operator.

    So I suggest looking up and using the std::string class (which is in the C++ header named <string>, not <string.h>) as the key for your map. And eliminate the usage of headers <stdio.h>, <stdlib.h>, and <string.h>.

    I'm not suggesting C techniques are bad. However, they generally do not play well with techniques used in C++.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    269
    Quote Originally Posted by grumpy View Post
    Roughly speaking, templates cannot be instantiated using types that are local to a function.
    Turns out that there is a way to do this. After 2003, the compile option -std=c++0x allows you to do this. Older g++ versions won't allow this.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 07-24-2012, 10:41 AM
  2. undefined reference to `RunSwmmDll(char*, char*, char*)'
    By amkabaasha in forum C++ Programming
    Replies: 1
    Last Post: 10-31-2011, 12:33 PM
  3. Replies: 8
    Last Post: 12-08-2009, 02:47 AM
  4. Read File To Char Array with Null char init
    By MicroFiend in forum Windows Programming
    Replies: 1
    Last Post: 10-28-2003, 06:18 PM
  5. Assigning Const Char*s, Char*s, and Char[]s to wach other
    By Inquirer in forum Linux Programming
    Replies: 1
    Last Post: 04-29-2003, 10:52 PM